package com.edu.web.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.entity.PageBean;
import com.edu.entity.User;
import com.edu.entity.shopDingdong;
import com.edu.service.UserBackgroundService;
import com.edu.service.impl.UserBackgroundServiceImpl;

/**
 * Servlet implementation class selectByShopServlet
 */
@WebServlet("/selectByShopServlet")
public class selectByShopServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public selectByShopServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		long sId = -1;
		double sprice = -1;
		
		
		String result = request.getParameter("currentPageNum");
		String pageSizeS = request.getParameter("pageSize");
		
		int currentPageNum = Integer.parseInt(result==null?"1":result);
		int pageSize = Integer.parseInt(pageSizeS==null?"5":pageSizeS);//显示记录数
		
		String shopId = request.getParameter("shopId");
		String shopName = request.getParameter("shopName");
		String shopUrl = request.getParameter("shopUrl");
		String shopPrice = request.getParameter("shopPrice");
		String shopType = request.getParameter("shopType");


		request.setAttribute("shopId", shopId);
		request.setAttribute("shopName", shopName);
		request.setAttribute("shopUrl", shopUrl);
		request.setAttribute("shopPrice", shopPrice);
		request.setAttribute("shopType", shopType);

		System.out.println("这是shopid："+shopId);
		System.out.println("这是shopname："+shopName);
		System.out.println("这是shopUrl："+shopUrl);
		System.out.println("这是shopPrice："+shopPrice);
		if(shopId!=null && !"".equals(shopId)){
			sId = Long.parseLong(shopId);
		}
		if(shopPrice!=null && !"".equals(shopPrice)){
			sprice = Double.parseDouble(shopPrice);
		}
		
		shopDingdong shop=new shopDingdong(sId, shopUrl, shopName, sprice,shopType);
		UserBackgroundService userBackService = new UserBackgroundServiceImpl();
		PageBean<shopDingdong> pageBean = userBackService.selectByShop(shop, currentPageNum, pageSize);
		System.out.println(pageBean);
		request.setAttribute("pageBean",pageBean);
		//response.sendRedirect("selectByUser.jsp");
		request.getRequestDispatcher("selectByShop.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
